<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    /*  const promise = new Promise((resolve, reject) => {
         console.log(1);
         resolve();
         console.log(2);
         reject()
     })
     setTimeout(() => { console.log(5) }, 0)   // cb1
     promise.then(() => { console.log(3) })  // cb 2 3 
         .then(() => { console.log(6) })
         .catch(() => { console.log(7) })
     console.log(4) */


    // 1  2  4  3  6  5 


    const first = () => (new Promise((resolve, reject) => {
        console.log(3);
        let p = new Promise((resolve, reject) => {
            console.log(7);
            setTimeout(() => {
                console.log(5);
                resolve();
            }, 0);
            resolve(1);
        });
        resolve(2);
        p.then((arg) => {
            console.log(arg);
        });
    }));
    first().then((arg) => {
        console.log(arg);
    });
    console.log(4);


</script>

</html>